home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / rpm-3.0.6 / http.req < prev    next >
Encoding:
Text File  |  2001-04-06  |  3.1 KB  |  127 lines

  1. #!/usr/bin/perl
  2.  
  3. # This file can find requirements of html and jhtml files (cgi, gif,
  4. # java dependencies).  It is a bit of a hack but it turns out to work
  5. # well.  We track only dependencies between Relative URLs, absolute
  6. # URL's are assumed to be extenernal to the RPM system.  We do not
  7. # parse the HTML but look through the set of strings (text surrounded
  8. # by quotes) for something which looks like a reference.  This avoids
  9. # writing a full HTML parsers and tends to work really well.  In this
  10. # manner we can track dependencies for: href, src, action and other
  11. # HTML tags which have not been invented yet.
  12.  
  13.  
  14. # The reference:
  15. #
  16. #    href="http://www.perl.org/images/arrow.gif"
  17. #
  18. # does not create a dependency but the reference
  19. #
  20. #    href="images/arrow.gif"
  21. #
  22. # will create a dependency.  
  23.  
  24. # Additionally this program will find the requirements for sun jhtml
  25. # (html with embedded java) since jhtml is deprecated so is this part
  26. # of the code.
  27.  
  28.  
  29. use File::Basename;
  30.  
  31. # this is the pattern of extensions to call requirements
  32.  
  33. $DEPS_PAT = '\.((cgi)|(ps)|(pdf)|(png)|(jpg)|(gif)|(tiff)|(tif)|(xbm)|(html)|(htm)|(shtml)|(jhtml))$'; #'
  34.  
  35. if ("@ARGV") {
  36.   foreach (@ARGV) {
  37.     process_file($_);
  38.   }
  39. } else {
  40.   
  41.   # notice we are passed a list of filenames NOT as common in unix the
  42.   # contents of the file.
  43.   
  44.   foreach (<>) {
  45.     process_file($_);
  46.   }
  47. }
  48.  
  49.  
  50.  
  51. foreach $key (sort keys %seen) {
  52.   print "$key\n";
  53. }
  54.  
  55.  
  56. sub process_file {
  57.  
  58.   my ($file) = @_;
  59.   chomp $file;
  60.   
  61.   open(FILE, "<$file")||
  62.     die("$0: Could not open file: '$file' : $!\n");
  63.   
  64.   # we have to suck in the whole file at once because too many people
  65.   # split lines around <java></java> tags.
  66.   
  67.   my (@file) = <FILE>;
  68.   
  69.   $_= "@file";
  70.  
  71.   # ignore line based comments ( careful although it has two slashes
  72.   # 'http://www.yahoo.com' is not a comment! )
  73.  
  74.   s!^\s*//.*$!!mg;
  75.   s!//\s.*$!!mg;
  76.   s!\s//.*$!!mg;
  77.   
  78.   # ignore multi-line comments 
  79.   # (use non greedy operators)
  80.   
  81.   s!/\*.*?\*/!!g;
  82.   s/<!--.*?-->//g;
  83.  
  84.   # html references other html documents inside strings.  Ignore non
  85.   # relative references since these dependencies can not be met. (ie,
  86.   # no package you install will ever provide 'http://www.yahoo.com').
  87.   # I use basename since I have seen too many http references which
  88.   # begin with '../' this would just kill the dependnecy tracking
  89.   # mechanism.
  90.  
  91.   while ( m{\"([^\"]+)\"}g ) {
  92.     my $string = $1;
  93.     chomp $string;
  94.     if ( ( $string !~ m!http://! ) &&
  95.      ( $string =~ m!$DEPS_PAT! ) ) {
  96.       $string = basename($string);
  97.       $string =~ s!\s+!!g;
  98.       $seen{"http(${string})"} = 1;
  99.     }
  100.   }
  101.  
  102.   {
  103.  
  104.   # This section is only for use with (Sun) jhtml dependencies, and
  105.   # since jhtml is deprecated so is this code.
  106.  
  107.   # java imports in jhtml (may have stars for leaf class)
  108.   # these may span several lines
  109.   
  110.     while (  m!<java type=((import)|(extends))>\s*([^<]+)\s*<!g ) {
  111.       my $java_list = $4;
  112.       $java_list =~ s/;/ /g;
  113.       $java_list =~ s/\n+/ /g;
  114.       $java_list =~ s/\s+/ /g;
  115.       foreach $java_class ( split(/\s+/, $java_list) ) {
  116.     $seen{"java(${java_class})"} = 1;
  117.       }
  118.     }
  119.     
  120.   }
  121.  
  122.   close(FILE, "<$file")||
  123.     die("$0: Could not close file: '$file' : $!\n");
  124.   
  125.   return ;
  126. }
  127.